﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ImTag.Silverlight
{
    public partial class Thumbnail : UserControl
    {
        public Thumbnail()
        {
            InitializeComponent();

            this.Image.MouseLeftButtonDown += (source, ev) =>
                {
                    MainPage.Current.ImageDisplayPanel.Thumbnail = this;
                };
        }
        private string imagePath;
        public string ImagePath
        {
            set
            {
                this.imagePath = value;
                this.Image.Source = new BitmapImage(new Uri(System.Windows.Browser.HtmlPage.Document.DocumentUri, value));
            }
            get { return this.imagePath; }
        }
        public IEnumerable<string> Tags
        {
            get { return this.TagPanel.Children.OfType<Tag>().Select(t => t.TagText); }
            set
            {
                this.TagPanel.Children.Clear();
                if(value != null)
                    foreach (var tag in value)
                        this.TagPanel.Children.Add(new Tag() { TagText = tag});
            }
        }
        public void AddTag(string tag)
        {
            if(tag != null)
                this.TagPanel.Children.Add(new Tag() { TagText = tag });
        }
    }
}
